var express = require('express');
var router = express.Router();
var User = require("../model/user.js");
/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});
router.post('/add', function (req, res, next) {
    var name = req.body.Name;
    var age = req.body.Age;
    var sex = req.body.Sex;
    insert(name,age,sex);
    res.send(true);
});

//插入
function insert(name,age,sex) {
    var user = new User({
        Name: name,                 
        Age: age,                     
        Sex: sex,                        
    });
    user.save(function (err, res) {
        if (err) {
            console.log("error:" + err);
        }
        else {
            console.log("res:" + res);
        }
            
    });
}
module.exports = router;
